import java.util.Scanner;

/**
 * @author caesar
 * @date 2025/6/30
 * @apiNote
 */
//计算这一天是这一年的第几天
//（1）从键盘分别输入年、月、日，判断这一天是当年的第几天。
//（2）要求要对输入值进行合法性的判断，确保输入的年份值必须大于0，月份值必须在[1,12]之间，日期值必须在[1, 当月最大日期值]范围内。
public class homework1_6 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        //验证数据输入正确
        int year;

        while (true) {
            System.out.print("请输入年份：");
            year = input.nextInt();
            if (year > 0) break;
            else {
                System.out.println("输入年份有误，请重新输入：");
            }
        }
        int month;
        while (true) {
            System.out.print("请输入月份：");
            month = input.nextInt();
            if (month >= 1 && month <= 12) break;
            else {
                System.out.println("输入月份有误，请重新输入：");
            }
        }
        int day;
        int standard = switch (month) {
            case 1, 3, 5, 7, 8, 10, 12 -> 31;
            case 4, 6, 9, 11 -> 30;
            case 2 -> year % 4 == 0 && year % 100 != 0 || year % 400 == 0 ? 29 : 28;
            default -> 0;
        };
        while (true) {
            System.out.print("请输入日期：");
            day = input.nextInt();
            if (day > 0 && day <= standard) break;
            else {
                System.out.println("输入日期有误，请重新输入：");
            }
        }
        //开始计算
        int sum = day;
        for (int i = 1; i < month; i++) {
            if (i == 2) {
                sum += (year % 4 == 0 && year % 100 != 0 || year % 400 == 0 ? 29 : 28);
            }
            if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12) {
                sum += 31;
            }
            if (i == 4 || i == 6 || i == 9 || i == 11) {
                sum += 30;
            }
        }
        System.out.println(year + "年" + month + "月" + day + "日是当年的第" + sum + "天");
        input.close();
    }
}
